Skip to content

aoモジュール

バージョン: 0.0.3

aoプロセスの通信はメッセージによって処理され、各プロセスはANS-104 DataItems形式でメッセージを受信し、以下の一般的な操作を実行できる必要があります。

  • isTrusted(msg) - このメッセージが信頼できるかどうかを確認
  • send(msg) - 別のプロセスにメッセージを送信
  • spawn(module, msg) - プロセスを生成

このライブラリの目的は、ao開発者ツールキットの中でこのコア機能を提供することです。開発者として、このライブラリを利用するかどうかは任意ですが、デフォルトで統合されています。

プロパティ

NameDescriptionType
idProcess Identifier (TXID)string
_moduleModule Identifier (TXID)string
authoritiesSet of Trusted TXsstring
AuthorityIdentifiers that the process is able to accept transactions from that are not the owner or the process (0-n)string
_versionThe version of the librarystring
envEvaluation Environmentstring
outboxHolds Messages and Spawns for responseobject

メソッド

send(msg: Message<table>) : Message<table>

send関数は、メッセージオブジェクトまたは部分的なメッセージオブジェクトを受け取り、オブジェクトに追加のao特有のタグを追加して完全なメッセージオブジェクトを返します。また、ao.outbox.Messagesテーブルにも挿入されます。

パラメータ

  • msg

スキーマ

json
{
    "type": "object",
    "properties": {
        "Target": {
            "type": "string",
            "description": "Process/Wallet to send message to"
        },
        "Data": {
            "type": "any",
            "description": "data to send in message DataItem"
        },
        "Tags": {
            "type": "object or array<name,value>"
            "description": "This property can be an array of name,value objects or an object"
        }
    }
}

Example 1

lua
local message = ao.send({
    Target = msg.From,
    Data = "ping",
    Tags = {
        {
            name = "Content-Type",
            value = "text/plain"
        }
    }
})

Example 2

lua
local message = ao.send({
    Target = msg.From,
    Data = "ping",
    Tags = {
        "Content-Type" = "text/plain"
    }
})

returns

Schema

json
{
    "type": "object",
    "properties": {
        "Target": {
            "type": "string"
        },
        "Data": {
            "type": "any"
        },
        "Tags": {
            "type": "array"
            "description": "name/value array",
            "items": {
                "type": "object",
                "properties": {
                    "name": {"type": "string"},
                    "value":{"type":"string"}
                }
            }
        }
    }
}

spawn(module : string, spawn : Spawn<table>) : Spawn<table>

spawn関数は、最初の引数としてモジュールのTXIDと、完全または部分的なSpawnテーブルを受け取ります。結果として、完全なSpawnテーブルが返されます。また、spawn関数は一意の参照識別子を持つRef_タグも生成します。

パラメータ

NameDescriptionType
moduleThe TXID that identifies the module binary to use to instaniate the process withstring
spawnThe spawn full or parital table object that contains the Data and Tags propertiestable

Schema

module

json
{
  "type": "string"
}

spawn

json
{
  "type": "object",
  "properties": {
    "Data": { "type": "any" },
    "Tags": {
      "type": "object or array",
      "description": "can be either <name,value> array, or object"
    }
  }
}

returns

Schema

json
{
  "type": "object",
  "properties": {
    "Data": { "type": "any" },
    "Tags": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "value": { "type": "string" }
        }
      }
    }
  }
}

isTrusted(msg : Message<table>) : boolean

プロセスを生成する際に、0個以上の権限タグを指定できます。aoライブラリは、これらの値をauthoritiesと呼ばれるaoプロパティのテーブル配列に追加します。このセットは、ao.TN.1のProof of Authority機能を提供します。メッセージがhandle関数に到着すると、開発者はao.isTrustedを呼び出して、そのメッセージが信頼できるソースからのものであるかを確認できます。

parameters

NameDescriptionType
msgMessage to check if trusted by this processtable

Schema

json
{
    "type": "object",
    "properties": {
        "Target": {
            "type": "string"
        },
        "Data": {
            "type": "any"
        },
        "Tags": {
            "type": "array"
            "description": "name/value array",
            "items": {
                "type": "object",
                "properties": {
                    "name": {"type": "string"},
                    "value":{"type":"string"}
                }
            }
        }
    }
}